$(function () {
    //等待加载
    loading();
    ajaxmyCollection(1);
    //oversize("productName", 18);
})

/**
 * 切换视频广告还是图片广告
 */
$(function () {
    $(".vedioAD").click(function () {
        $(".tcdPageCode").empty().unbind();
        $("#void").empty();
        //等待加载
        loading();

        $("#void").show();
        $("#pic").hide();
        $(".picAD").removeClass("current");
        $(this).addClass("current");
        ajaxmyCollection(1, null);
    });
    $(".picAD").click(function () {
        $(".tcdPageCode").empty().unbind();
        $("#pic").empty();
        //等待加载
        loading();
        $("#void").hide();
        $("#pic").show();
        $(".vedioAD").removeClass("current");
        $(this).addClass("current");
        var ad_type = "picture";
        ajaxmyCollectionpic(1, ad_type);
    })
})


/**
 * 我的收藏的广告
 *
 * @param page
 *            当前页数
 * @param ad_type
 *            广告类型 video是视频广告，picture是图片广告
 * @returns
 */

function ajaxmyCollection(page) {
    var url = "/Lvscore_User_M/myAds/ajaxmyCollection";
    $.post(url, {
        page: page,
        ad_type: "video"
    }, function (data) {
        // sumpage：页容量（页面的数据条数）
        // nowpage：页码

        // adsList：List<AdInfoBean>
        // id:广告Id
        // name：广告名
        // duration：视频时间
        // price：价格
        // plan_start：投放开始时间
        // plan_end：投放结束时间
        // pc_version_url：pc端路径
        // status：投放状态
        $("#void").empty();
        $("#pic").empty();
        if (data.adslist.length == 0) {
            $("#void").html('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">您暂时没有收藏任何视频广告</p>');
        } else {
            $.each(data.adslist, function (index, element) {
                if (!isNotEmpty(element.ad_homepage)) {
                    element.ad_homepage = "/Lvscore_User_M/userWeb/static/images/bm.png";
                }
                if (!isNotEmpty(element.pc_size)) {
                    element.pc_size ='未知';
                }
                if (!isNotEmpty(element.play_num)) {
                    element.play_num ='0';
                }
                if (!isNotEmpty(element.duration)) {
                    element.duration ='未知';
                }
                $("#void").append("<li>" +
                    "<span class='hintbg'></span>" +
                    "<span class='center'><span class='productName'>" + getTitle(element.name) + "</span><b><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png' alt='' title=''>" + element.price + "</b></span>" +
                    "<img src='" + element.ad_homepage + "' class='bjHover' width='235px' height='135px'>" +
                    "<div class='backdrop'>" +
                    "<div class='bj'></div>" +
                    "<h2>" + getTitle(element.name) + "</h2>" +
                    "<p>有效期至：" + element.plan_end + "</p>" +
                    "<i>" + element.duration + "&quot;</i>" +
                    "<ol>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png'></span>" + element.price + "</li>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon2.png'></span>" + element.pc_size + "</li>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon3.png'></span>" + element.play_num + "次</li>" +
                    "</ol>" +
                    "<input type='button' ad_type='video' ad_id='" + element.id + "' value='播放' class='plays'>" +
                    "</div>" +
                    "</li>");
                $(".recommendBox ul li").hover(function () {
                    $(this).find(".backdrop").show();
                }, function () {
                    $(this).find(".backdrop").hide()
                });
            });
            //分页
            if ($(".tcdPageCode").html() == "") {
                createPageVideo(data.sumpage, data.nowpage);
            }
            playAd();
        }
        //等待加载的效果消失
        $(".loadingBox").hide();
    }, "json");
}

/**
 * 我的收藏的广告图片广告
 * @param page当前页数
 * @returns
 */
function ajaxmyCollectionpic(page) {
    var url = "/Lvscore_User_M/myAds/ajaxmyCollection";
    $.post(url, {
        page: page,
        ad_type: "picture"
    }, function (data) {
        $("#pic").empty();
        if (data.adslist.length == 0) {
            $("#pic").html('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">您暂时没有收藏任何图片广告</p>');
            //等待加载的效果消失
            $(".loadingBox").hide();
        }
        $.each(data.adslist, function (index, element) {
            if (!isNotEmpty(element.ad_homepage)) {
                element.ad_homepage = "/Lvscore_User_M/userWeb/static/images/bm.png";
            }
            if (!isNotEmpty(element.pc_size)) {
                element.pc_size ='未知';
            }
            if (!isNotEmpty(element.play_num)) {
                element.play_num ='0';
            }
            if (!isNotEmpty(element.duration)) {
                element.duration ='未知';
            }
            $("#pic").append("<li>" +
                "<span class='hintbg'></span>" +
                "<span class='center'><span class='productName'>" + getTitle(element.name) + "</span><b><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png' alt='' title=''>" + element.price + "</b></span>" +
                "<img src='" + element.ad_homepage + "' class='bjHover'>" +
                "<div class='backdrop'>" +
                "<div class='bj'></div>" +
                "<h2>" + getTitle(element.name) + "</h2>" +
                "<p>有效期至：" + element.plan_end + "</p>" +
                "<i>" + element.duration + "张</i>" +
                "<ol>" +
                "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png'></span>" + element.price + "</li>" +
                "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon2.png'></span>" + element.pc_size + "</li>" +
                "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon3.png'></span>" + element.play_num + "次</li>" +
                "</ol>" +
                "<input type='button' ad_type='pic' ad_id='" + element.id + "' value='播放' class='plays'>" +
                "</div>" +
                "</li>");
            $(".recommendBox ul li").hover(function () {
                $(this).find(".backdrop").show();
            }, function () {
                $(this).find(".backdrop").hide()
            });
        });
        if ($(".tcdPageCode").html() == "") {
            createPagePic(data.sumpage, data.nowpage);
        }
        //等待加载的效果消失
        $(".loadingBox").hide();
        playAd();
    }, "json");
}

/**
 * 图片广告分页
 * @param pages 当前页数
 * @param pageNum总页数
 * @returns
 */
function createPagePic(pages, pageNum) {
    if (pages > 1) {
        $(".tcdPageCode").createPage({
            pageCount: pages,
            current: pageNum,
            backFn: function (p) {
                ajaxmyCollectionpic(p);
            }
        });
    }
}


/**
 * 图片广告分页
 * @param pages 当前页数
 * @param pageNum总页数
 * @returns
 */
function createPageVideo(pages, pageNum) {
    if (pages > 1) {
        $(".tcdPageCode").createPage({
            pageCount: pages,
            current: pageNum,
            backFn: function (p) {
                ajaxmyCollection(p);
            }
        });
    }
}

	
            